/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//parse to XML
function stringtoXML(text){
    var doc;
    if (window.ActiveXObject){ //IE browser only
        doc=new ActiveXObject('Microsoft.XMLDOM');
        doc.async=false;
        doc.loadXML(text);

    } else {    //other browsers
        var parser=new DOMParser();
        doc=parser.parseFromString(text,'text/xml');
    }
    return doc;
}
function xmlToString(xmlDoc) {
    var str;
    if (window.ActiveXObject){ //IE browser only
        str = xmlDoc.xml;

    } else {    //other browsers
        str = (new XMLSerializer()).serializeToString(xmlDoc);
    }
    return str;
}

function queryOneNode(xpath,doc,resolver){
    var node;
    var result;
    if (window.ActiveXObject){
        result = doc.selectNodes(xpath);
        node = result.item(0);
    } else {
        result = doc.evaluate(xpath, doc, resolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE ,null);
        node = result.iterateNext();
    }
    return node;
}
function queryLists(xpath,doc,resolver){
    var result;
    var nodeList;
    
    if (window.ActiveXObject){
        result = doc.selectNodes(xpath);
        nodeList = result;
        
    } else {
        nodeList = new Array();
        result = doc.evaluate(xpath, doc, resolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE ,null);

        var node = result.iterateNext();
        var i = 0;
        while (node) {
            nodeList[i] = node.cloneNode(true);
            node = result.iterateNext();
            i++;
        }
    }
    return nodeList;
}

function copyArray(arr) {
    var result = new Array();
    for(i=0; i < arr.length; i++) {
        result[i] = arr[i];
    }
    return result;
}
